<?php

namespace Admin\Controller;

use Zend\View\Model\ViewModel;
use Admin\Model\DBO\ReaderDBO;
use Admin\Controller\IndexController;

class ListReaderController extends IndexController {

    public $userTable;

    /*
     * Nếu không phải là quyền admin thì ko thể vào đây
     */

    public function indexAction() {
        // kiem tra neu chua dang nhap thi quay ve lai trang dang nhap
        $this->checkRole2();
        // Neu dang nhap roi thi hien thi len sach sach nguoi dung
        // Lay thuc the dang nhap dua ra layout
        $this->layout()->identity = $this->getAuthService()->getIdentity();
        $objectReader = new ReaderDBO($this->getServiceLocator());
        // Hien thi dua sanh sach nguoi dung ra view
        $paginator = $objectReader->fetchAllReader(true);
        // set the current page to what has been passed in query string, or to 1 if none set
        $paginator->setCurrentPageNumber((int) $this->params()->fromQuery('page', 1));
        // set the number of items per page to 10
        $paginator->setItemCountPerPage(15);
        $paginator->setPageRange(5);

        return new ViewModel(array(
            'paginator' => $paginator
        ));
    }

    public function detailReaderAction() {
        $this->checkRole2();
        // Neu dang nhap roi thi hien thi len sach sach nguoi dung
        // Lay thuc the dang nhap dua ra layout
        $this->layout()->identity = $this->getAuthService()->getIdentity();
        $cardBarcode = $this->params()->fromRoute('id', 0);
        $cardBarcode = str_replace('-', '.', $cardBarcode);
        if (!$cardBarcode) {
            return $this->redirect()->toRoute('list-reader');
        }
        $objectReaderDBO = new ReaderDBO($this->getServiceLocator());
        $infoReader = $objectReaderDBO->getInfoReaderFromBarcode($cardBarcode);
        return array(
            'infoReader' => $infoReader,
        );
    }

}